package com.hhx.test_library.mvp.presenter;

import android.content.Context;

import com.hhx.baselibrary.bean.BaseResponse;
import com.hhx.baselibrary.net.ObserverResponseListener;
import com.hhx.baselibrary.net.exception.ApiException;
import com.hhx.test_library.mvp.contract.AContract;
import com.hhx.test_library.mvp.model.AModel;

import java.util.HashMap;

/**
 * Created by Administrator on 2019/2/22.
 */

public class APresenter extends AContract.Presenter {

    private Context mContext;
    private AModel model;

    public APresenter(Context mContext) {
        this.mContext = mContext;
        model = new AModel();
    }

    @Override
    public void login(HashMap<String, Object> map, boolean isDialog, boolean cancelable) {
        model.login(mContext, map, isDialog, cancelable, getView().bindLifecycle(), new ObserverResponseListener() {
            @Override
            public void onNext(Object o) {
                if (getView() != null) {
                    getView().refreshSuccess((BaseResponse) o);
                }
            }

            @Override
            public void onError(ApiException e) {
                if (getView() != null) {
                    getView().refreshFailed(e.getMessage());
                }
            }
        });
    }
}
